package com.bt.lms.ui.action.teaching.plan.utils;

import com.bt.lms.network.msg.ReqMsg;
import com.bt.lms.network.msg.packet.ReqMsgPacket;
import com.bt.lms.utils.Convert;

/**
 * 请求消息包
 * @author 李舒淇
 */
public class HandleTowReqMsgPacket {

    /**
     * 3.将用户输入的信息处理成我们规定的请求消息
     * @param reqMsg  用户输入
     * @return  请求消息包
     */
    public static ReqMsgPacket handle2ReqMsgPacket(ReqMsg reqMsg) {

        String magicNo = reqMsg.getMagicNo();//魔数
        Byte version = reqMsg.getVersion();//协议版本号
        Byte serialCou = reqMsg.getSerialCou();//序列化算法
        Byte evenType = reqMsg.getEvenType();//事件类型
        Short busType = reqMsg.getBizType();//业务类型
        Byte twoWay = reqMsg.getTwoWay();//2Way
        Long reqID = reqMsg.getReqId();//请求 id
        byte[] remainField = reqMsg.getRemainField();//保留字段
        String data = reqMsg.getData();//数据
        ReqMsgPacket reqMsgPacket = new ReqMsgPacket();
        reqMsgPacket.setMagicNo(magicNo.getBytes());//魔数
        reqMsgPacket.setVersion(version);//
        reqMsgPacket.setSerialCou(serialCou);
        reqMsgPacket.setEvenType(evenType);
        reqMsgPacket.setBizType(Convert.shortToBytes(busType));
        reqMsgPacket.setTwoWay(twoWay);
        reqMsgPacket.setReqID(Convert.longToBytes(reqID));
        reqMsgPacket.setRemainField(remainField);
        reqMsgPacket.setDataLen(Convert.intToBytes(data.length()));
        reqMsgPacket.setData(data.getBytes());



        return reqMsgPacket;


    }
}
